package com.ymatou.iapi.couponmanage.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.couponmanage.parameter.SetSellerBatchOpenBean;
import com.ymatou.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymatou.iapi.couponmanage.service.SetSellerBatchOpenCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.sqlwapper.couponbatchWapper;
//import com.ymttest.database.model.couponbatch;
//import com.ymttest.database.sqlwapper.couponbatchWapper;
/**
*设置商家批次无门槛开关信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetSellerBatchOpen{
	private static SetSellerBatchOpenBean setsellerbatchopenBean;
	private static SetSellerBatchOpenCall setsellerbatchopenCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商家批次无门槛开关信息");
	}

	@Before
	public void caseUp() {
		setsellerbatchopenBean=new SetSellerBatchOpenBean();
		setsellerbatchopenCall=new SetSellerBatchOpenCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setsellerbatchopenCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_001() {
		Logger.start(true,"开启商家批次无门槛开关信息-设置前关闭");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatchBean();
			sellercreatebatchBean.setIsShowOnPage(false);
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			Logger.verifyEquals(true, batch.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_002() {
		Logger.start(true,"关闭商家批次无门槛开关信息-设置前开启");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(false);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Logger.verifyEquals(false, batch.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_003() {
		Logger.start(true,"开启商家批次无门槛开关信息--设置前 开启");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Logger.verifyEquals(true, batch.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_010() {
		Logger.start(true,"关闭商家批次无门槛开关信息-设置前关闭");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatchBean();
			sellercreatebatchBean.setIsShowOnPage(false);
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(false);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Logger.verifyEquals(false, batch.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_004() {
		Logger.start(true,"开启商家批次无门槛开关信息-SellerId空");
		try {

			setsellerbatchopenBean.setBatchId(12344);
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
//			Logger.verifyEquals("2", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyIsContains(true, setsellerbatchopenCall.getMessage().contains("请传入商家ID"), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_005() {
		Logger.start(true,"开启商家批次无门槛开关信息-BatchId空");
		try {

			setsellerbatchopenBean.setSellerId(12344);
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
//			Logger.verifyEquals("2", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyIsContains(true, setsellerbatchopenCall.getMessage().contains("请传入商家批次ID"), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_006() {
		Logger.start(true,"开启商家批次无门槛开关信息-IsOpen空,默认为false");
		try {
			Map batch  = new couponbatchWapper().getTop1SellerCouponInfo().get(0);

			setsellerbatchopenBean.setSellerId(Integer.parseInt(batch.get("OperatorId").toString()));
			setsellerbatchopenBean.setBatchId(Integer.parseInt(batch.get("BatchId").toString()));
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			couponbatch batch1 = new couponbatchWapper().selectByPrimaryKey(Integer.parseInt(batch.get("BatchId").toString()));
			
			Logger.verifyEquals(false, batch1.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_007() {
		Logger.start(true,"开启商家批次无门槛开关信息-seller与batchid不匹配");
		try {
			Map batch  = new couponbatchWapper().getTop1SellerCouponInfo().get(0);

			setsellerbatchopenBean.setSellerId(33835);
			setsellerbatchopenBean.setBatchId(Integer.parseInt(batch.get("BatchId").toString()));
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
//			Logger.verifyEquals("2", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyIsContains("您没有权限作废此批次，请勿非法操作", setsellerbatchopenCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_008() {
		Logger.start(true,"开启已开启的商家批次无门槛开关信息");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatchBean();
			sellercreatebatchBean.setIsShowOnPage(true);
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Logger.verifyEquals(true, batch.getIsShowInPage(), "验证数据库IsShowInPage");
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("0", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", setsellerbatchopenCall.getMessage(), "验证返回Message");

			batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
			
			Logger.verifyEquals(true, batch.getIsShowInPage(), "验证数据库IsShowInPage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_009() {
		Logger.start(true,"开启商家批次无门槛开关信息-批次不存在");
		try {
			Map batch  = new couponbatchWapper().getTop1SellerCouponInfo().get(0);

			setsellerbatchopenBean.setSellerId(Integer.parseInt(batch.get("OperatorId").toString()));
			setsellerbatchopenBean.setBatchId(2423525);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
//			Logger.verifyEquals("2", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyIsContains("批次不存在", setsellerbatchopenCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSellerBatchOpen_011() {
		Logger.start(true,"开启商家批次无门槛开关信息-平台活动批次-JIRACONN-23166");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellercreatebatchBean = CouponServiceMCallServiceV2.setDefaultSellerCreateBatch_ActivityBean();
			sellercreatebatchBean.setIsShowOnPage(false);
			SellerCreateBatchCall sellerCreateBatchCall = CouponServiceMCallServiceV2.SellerCreateBatch(sellercreatebatchBean);
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sellerCreateBatchCall.getBatchCode()).get(0);
		
			setsellerbatchopenBean.setSellerId(batch.getOperatorId());
			setsellerbatchopenBean.setBatchId(batch.getBatchId());
			setsellerbatchopenBean.setIsOpen(true);
			
			setsellerbatchopenCall.setData(setsellerbatchopenBean);
			setsellerbatchopenCall.callService();			
			
			Logger.verifyEquals("2", setsellerbatchopenCall.getCode(), "验证返回code");
			Logger.verifyEquals(true, setsellerbatchopenCall.getMessage().contains("批次不允许此操作"), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}



